'''
Author: goog
Date: 2021-12-15 21:14:46
LastEditTime: 2022-01-13 14:35:12
LastEditors: goog
Description: 
FilePath: /chengdu/TensorRT20220110/DetectionFM/XS/XS.py
Time Limit Exceeded!
'''
import os
import json

def xs(cfg, item, barcode):
    defect = "XS"
    abs_dir = cfg['abs_dir']
    config_path = os.path.join(abs_dir, 'DetectionFM/'+defect+'/'+defect+'.json')
    with open(config_path, 'r') as fp:
        config = json.load(fp)
        
        if barcode[1:3] in ['53', '54', '55', '56', '57', '58', '61', '1H', '2H']:
            barcode = 'C61'+barcode[3:]

        elif barcode not in config.keys():
            barcode = 'C50'+barcode[3:]
        # else:
        #     print('xs error')
        
        flag = config[barcode]['exist']
   
    if 'xs' not in item.keys():
        return False == flag

    xs_position = item['xs']
    xs_conf = item['xs'][0][-1]
    if len(xs_position)>0 and xs_conf>0.3:
        return True == flag
    else: 
        return False == flag